/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.tukano.treditor;

import it.tukano.app.AppContext;
import it.tukano.swingdeco.joptionpane.JOptionPaneExt;
import it.tukano.treditor.modules.AppSettingsModule;
import it.tukano.treditor.modules.ConsoleModule;
import it.tukano.treditor.modules.DataModel;
import it.tukano.treditor.modules.DirectionalLightEditor;
import it.tukano.treditor.modules.EngineManager;
import it.tukano.treditor.modules.HelpSystemModule;
import it.tukano.treditor.modules.IOModule;
import it.tukano.treditor.modules.MainFrame;
import it.tukano.treditor.modules.ModelPropertiesForm;
import it.tukano.treditor.modules.ModelStore;
import it.tukano.treditor.modules.PickTool;
import it.tukano.treditor.modules.SceneGraphPopup;
import it.tukano.treditor.modules.SceneGraphViewer;
import it.tukano.treditor.modules.SceneViewForm;
import it.tukano.treditor.modules.ToolbarModule;
import it.tukano.treditor.modules.TreditorFileReader;
import it.tukano.treditor.modules.TreditorFileWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPopupMenu;

/**
 * Starts the application
 * @author pgi
 */
public class Main {
    
    /**
     * Entry point
     * @param args command line arguments 
     */
    public static void main(String[] args) {
        Logger.getLogger("com.jme3").setLevel(Level.SEVERE);
        java.awt.EventQueue.invokeLater(new Runnable() {
            
            @Override
            public void run() {
                new Main().edtStart();
            }
        });
    }

    /**
     * Called in the edt, initializes the modules and start the application
     */
    public void edtStart() {
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
        boolean engineNotAvailable = true;
        
        final String engineClassName = "it.tukano.treditor.engine.jme3.JME3Engine";
        final boolean loadEngine = true;
        final AppContext context = new AppContext();
        
        if(loadEngine) try {
            context.append(new EngineManager(engineClassName));
            engineNotAvailable = false;
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        if(engineNotAvailable) {
            JOptionPaneExt.showMessageDialog(null, "Engine cannot be load. Program won't be fully functional.");
        }
        
        context.append(new IOModule());
        context.append(new AppSettingsModule());
        context.append(new ModelStore());
        context.append(new ConsoleModule());
        context.append(new MainFrame());
        context.append(new SceneGraphViewer());
        context.append(new SceneGraphPopup());
        context.append(new DataModel());
        context.append(new SceneViewForm());
        context.append(new TreditorFileReader());
        context.append(new TreditorFileWriter());
        context.append(new ModelPropertiesForm());
        context.append(new DirectionalLightEditor());
        context.append(new HelpSystemModule());
        context.append(new ToolbarModule());
        context.append(new PickTool());

        context.initModule(context);
        context.startModule(context);
    }
}
